<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="icon.jpg">

    <title>Signin</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="js/ie10-viewport-bug-workaround.js"></script>

      <!-- Placed at the end of the document so the pages load faster -->
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="container">
<form class="form-signin">
  <h2 class="form-signin-heading">监控系统3.0</h2>
  <label for="userName" class="sr-only">用户名</label>
  <input type="text" id="nickname" class="form-control" placeholder="用户名" required autofocus>
  <label for="inputPassword" class="sr-only">Password</label>
  <input type="password" id="password" class="form-control" placeholder="密码" required>
  <!--<div class="checkbox">
      <label>
          <input type="checkbox" value="remember-me"> 记住
      </label>
  </div>-->
  <button id="submit" class="btn btn-lg btn-primary btn-block" type="submit">登陆</button>
</form>
<p class="loginErrorInfo"></p>
</div> <!-- /container -->
<script>
//  如果 改变 条状的 页面名称 这个变量需要做想相应改变
  var monitor = "monitor.html";

  $().ready(function() {
      $(".form-signin").submit(function(event){
          login();
          event.preventDefault();
      });


function login(){
                    var errInfo = "";
                    $(".loginErrorInfo").text(errInfo);
                    var url = "/sso/login?clientTime="+new Date().getTime()+"&serviceId=hollycc&__srcurl=";
                    var search = location.search;

                    if(search && search.length > 0){
                        url += search.substr(1);
                    }else{
                        url += "/";
                    }
                    var status,errInfo = "";
                    $.get("/license/alarm?nickname="+$("#nickname").val(), function(data){
                        if(!data){
                            errInfo = "License校验失败!";
                            $(".loginErrorInfo ._text").text(errInfo);
                            return false;
                        }
                        if (data && data[0]) status = data[0];
                        if (data && data[1]) errInfo = data[1];
                        if(status == "1"){
                            $(".loginErrorInfo ._text").text(errInfo);
                            return false;
                        }
                        if($("#nickname").val() == "" || $("#password").val() == "") {
                            errInfo = "用户名/密码必须填写!";
                            $(".loginErrorInfo ._text").text(errInfo);
                            return false;
                        }else{
                            url += "&nickname=" + $("#nickname").val();
                            url += "&password=" + $("#password").val();
                        }
                        //debugger;

                        $.ajax({
                        type: 'POST',
                        url : url,
                        success: function(data) { //data.userId
                                if (data.__srcurl != null && data.__ticketId != null && data.__signature != null) {
                                    var hrefurl = data.__srcurl;
                                    if (hrefurl.indexOf("?") >= 0){
                                        hrefurl += "&";
                                    }else{
                                        hrefurl += "?";
                                    }
                                    createCookie("userId",data.userId,1);
                                    window.location.href = monitor;
                                    //location.href = hrefurl + "__ticketId=" + data.__ticketId + "&__signature=" + data.__signature;
                                }else{
                                    $(".loginErrorInfo").text(data);
                                }
                            },
                            error:function(XMLHttpRequest, textStatus, errorThrown){
                                var msg = "";
                                if(XMLHttpRequest.responseText.length != 0){
                                    msg = msg + XMLHttpRequest.responseText;
                                }
                                else {
                                    msg = "status:"+textStatus+";error:"+errorThrown;
                                }
                                $(".loginErrorInfo").text(msg);
                        }
                        });
                    });
                }

  });
</script>
</body>
</html>
